package io.nanfeng.coroutine

import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.reactor.flux
import kotlinx.coroutines.reactor.mono
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.withContext


val mutex = Mutex()

suspend fun foo() {
    mutex.lock()
    println("foo")
    try {
        doSomeWork()
    } finally {
        mutex.unlock()
    }
}

suspend fun doSomeWork() {
    mutex.lock()
    try {
        println("Working!")
    } finally {
        mutex.unlock()
    }
}

suspend fun main() {
    foo()
}